<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="3.0"
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               xmlns="http://www.w3.org/1999/xhtml"
               xmlns:java="com.uni.crawl.common.util.crawl"
               exclude-result-prefixes="java">

    <xsl:template match="//*[@id='__NEXT_DATA__']/text()">
        <root>
            <xsl:variable name="json" select="java:XsltFunc.replaceAll(.,'\s{8}','')"/>
            <xsl:variable name="xml" select="java:XsltFunc.toXmlStr($json)"/>
            <result>
                <xsl:value-of select="$xml"/>
            </result>
        </root>
    </xsl:template>

    <xsl:template match="/">
        <root>
            <xsl:for-each select="//posts">
                <articleList>
                    <title>
                        <xsl:value-of select="title"/>
                    </title>
                    <publishedAt>
                        <xsl:value-of select="published_at"/>
                    </publishedAt>
                    <userId>
                        <xsl:value-of select="user/id"/>
                    </userId>
                    <userNickName>
                        <xsl:value-of select="user/nickname"/>
                    </userNickName>
                    <detailUrl>
                        <xsl:value-of select="concat('https://eleduck.com/tposts/',normalize-space(user/id))"/>
                    </detailUrl>
                </articleList>
            </xsl:for-each>
        </root>
    </xsl:template>

</xsl:transform>